package cn.me.alphamq.broker.event.spi.listener.nameserver;

import cn.me.alphamq.broker.cache.Container;
import cn.me.alphamq.broker.event.model.nameserver.ChangeMasterEvent;
import cn.me.alphamq.common.event.Listener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 从 broker 更换主 broker 事件的监听器
 *
 * @author f
 */
public class ChangeMasterListener implements Listener<ChangeMasterEvent> {

    private static final Logger log = LoggerFactory.getLogger(ChangeMasterListener.class);

    @Override
    public void onReceive(ChangeMasterEvent event) throws Exception {
        // 让当前从 broker 与新的主 broker 建立连接
        Container.getSlaveSyncClient().initConnection(event.getNewMasterAddress());
        log.info("connect to new master successfully");
    }
}
